import socket

tcpServer = socket.socket(socket.AF_INET, socket.SOCK_STREAM) # 创建socket对象，走tcp通道
host = socket.gethostname() # 获取本地主机名
port = 1000 # 端口号
addr = (host, port)
tcpServer.bind(addr) # 绑定地址
tcpServer.listen(5) # 设置最大连接数，超过后排队

while True:
    conn,addr = tcpServer.accept() # 建立客户端连接
    print(conn)
    data = conn.recv(1024) # 接收来自客户端的数据，小于1024字节
    print(data)
    msg = 'Hello Client'.encode('utf-8')
    conn.send(msg) # 发送数据给客户端
    conn.close() # 关闭连接
    
